<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<link href="${ctx}resources/css/select/bootstrap-select.css" rel="stylesheet" type="text/css">
<%@ include file="/WEB-INF/common/head.jsp"%>
</head>
<body class="${cookie.bodyClass.value}">
	<div class="container body">
		<div class="main_container">
			<%@ include file="/WEB-INF/common/left.jsp"%>
			<%@ include file="/WEB-INF/common/top.jsp"%>
			<!-- page content -->
			<div class="right_col" role="main" id="main">
				<div class="x_panel">
					<div class="x_title">
						<h2>订单详情</h2>
						<div class="clearfix"></div>
					</div>
					<div class="x_content">
						<div class="modal-body">
							<form role="form" data-parsley-validate id="orderForm" class="form-horizontal">
								<div class="form-group item">
									<label for="name" class="col-sm-3 control-label">购买人昵称:<font color="red">*</font>
									</label>
									<div class="col-sm-6">
										<input type="text" class="form-control" value="${order.nickName}" readonly="readonly">
									</div>
								</div>
								<div class="form-group item">
									<label for="name" class="col-sm-3 control-label">购买人手机号:<font color="red">*</font>
									</label>
									<div class="col-sm-6">
										<input type="text" class="form-control" value="${order.cellphone}" readonly="readonly">
									</div>
								</div>
								<div class="form-group item">
									<label for="address" class="col-sm-3 control-label">下单时间:<font color="red">*</font>
									</label>
									<div class="col-sm-6">
										<input type="text" class="form-control cdTime" value="${order.showItems.createdTime}" readonly="readonly" >
									</div>
								</div>
								<c:if test="${order.payType!=null&&order.orderStatus!=0}">
								<div class="form-group item">
									<label for="address" class="col-sm-3 control-label">支付时间:<font color="red">*</font>
									</label>
									<div class="col-sm-6">
										<input type="text" class="form-control cdTime" value="${order.showItems.paidTime}" readonly="readonly" >
									</div>
								</div>
								</c:if>
								<div class="form-group item">
									<label for="address" class="col-sm-3 control-label">订单编号:<font color="red">*</font>
									</label>
									<div class="col-sm-6">
										<input type="text" class="form-control" value="${order.orderNumber}" readonly="readonly" >
									</div>
								</div>
								<div class="form-group item">
									<label for="address" class="col-sm-3 control-label">运费:<font color="red">*</font>
									</label>
									<div class="col-sm-6">
										<input type="text" class="form-control" value="${order.freight}" readonly="readonly">
									</div>
								</div>
								<div class="form-group item">
									<label for="address" class="col-sm-3 control-label">支付金额:<font color="red">*</font>
									</label>
									<div class="col-sm-6">
										<input type="text" class="form-control" value="${order.payMoney}" readonly="readonly">
									</div>
								</div>
								<div class="form-group item">
									<label for="address" class="col-sm-3 control-label">订单状态:<font color="red">*</font>
									</label>
									<div class="col-sm-6">
										<c:if test="${order.orderStatus=='0'}">
											<input type="text" class="form-control" value="待支付 " readonly="readonly">
										</c:if>
										<c:if test="${order.orderStatus=='1'}">
											<input type="text" class="form-control" value="待发货 " readonly="readonly">
										</c:if>
										<c:if test="${order.orderStatus=='2'}">
											<input type="text" class="form-control" value="待收货 " readonly="readonly">
										</c:if>
										<c:if test="${order.orderStatus=='3'}">
											<input type="text" class="form-control" value="待评价 " readonly="readonly">
										</c:if>
										<c:if test="${order.orderStatus=='4'}">
											<input type="text" class="form-control" value="交易完成" readonly="readonly">
										</c:if>
										<c:if test="${order.orderStatus=='5'}">
											<input type="text" class="form-control" value="交易取消" readonly="readonly">
										</c:if>
									</div>
								</div>
								<c:if test="${order.payType!=null&&order.orderStatus!=0}">
								<div class="form-group item">
									<label for="address" class="col-sm-3 control-label">支付类型:<font color="red">*</font>
									</label>
									<div class="col-sm-6">
										<c:if test="${order.payType=='0'}">
											<input type="text" class="form-control" value="积分兑换" readonly="readonly">
										</c:if>
										<c:if test="${order.payType=='1'}">
											<input type="text" class="form-control" value="支付宝" readonly="readonly">
										</c:if>
										<c:if test="${order.payType=='2'}">
											<input type="text" class="form-control" value="微信" readonly="readonly">
										</c:if>
									</div>
								</div>
								</c:if>
								<div class="form-group item">
									<label for="address" class="col-sm-3 control-label">收货人姓名:<font color="red">*</font>
									</label>
									<div class="col-sm-6">
										<input type="text" class="form-control" value="${address.receiverName } " readonly="readonly">
									</div>
								</div>
								<div class="form-group item">
									<label for="address" class="col-sm-3 control-label">收货人联系电话:<font color="red">*</font>
									</label>
									<div class="col-sm-6">
										<input type="text" class="form-control" value="${address.receiverCellphone } " readonly="readonly">
									</div>
								</div>
								<div class="form-group item">
									<label for="address" class="col-sm-3 control-label">收货人收货地址:<font color="red">*</font>
									</label>
									<div class="col-sm-6">
										<input type="text" class="form-control" value="${address.province}${address.city}${address.area}${address.receiverAddress} " readonly="readonly">
									</div>
								</div>
								<c:if test="${not empty order.logisticsCompany && not empty order.logisticsNumber}">
								<div class="form-group item">
									<label for="address" class="col-sm-3 control-label">物流公司:<font color="red">*</font>
									</label>
									<div class="col-sm-6">
										<input type="text" class="form-control" value="${order.logisticsCompany}" readonly="readonly">
									</div>
								</div>
								<div class="form-group item">
									<label for="address" class="col-sm-3 control-label">物流单号:<font color="red">*</font>
									</label>
									<div class="col-sm-6">
										<input type="text" class="form-control" value="${order.logisticsNumber}" readonly="readonly">
									</div>
								</div>
								</c:if>
								<div class="form-group item">
									<label for="address" class="col-sm-3 control-label">商品规格:<font color="red">*</font>   
									</label>
									<div class="col-sm-6">
										<table class="table table-bordered">
											<thead>
												<tr>
													<th>商品图片</th>
													<th>商品名称</th>
													<th>商品规格</th>
													<th>商品价格</th>
													<th>商品数量</th>
													<th>售后状态</th>
												</tr>
											</thead>
											<tbody>
												<c:forEach items="${order.showItems.orderItems}" var="orderItem">
													<tr>
														<td><img src="${imgDomain}/${orderItem.imageUrl}" width="100px;" height="50px;"> </td>
														<td>${orderItem.commodityName}</td>
														<td>${orderItem.specificationName}</td>
														<td>${orderItem.specificationPrice}</td>
														<td>${orderItem.quantity}</td>
														<td> 
														<c:if test="${orderItem.afterSalesStatus=='0'}">未申请售后</c:if> 
														<c:if test="${orderItem.afterSalesStatus=='1'}">申请售后待审核</c:if> 
														<c:if test="${orderItem.afterSalesStatus=='2'}">申请售后审核通过待打款</c:if> 
														<c:if test="${orderItem.afterSalesStatus=='3'}">申请售后拒绝</c:if> 
														<c:if test="${orderItem.afterSalesStatus=='4'}">已打款</c:if> 
														</td>
													</tr>
												</c:forEach>
											</tbody>
										</table>
									</div>
								</div>
							</form>
						</div>
						<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12" style="text-align:center">
							<button type="button" class="btn btn-dark btn-sm" onclick="back();">返回</button>
							<c:if test="${order.isAudit==0 and order.payType!=0}">
							<button type="button" class="btn btn-primary btn-sm" onclick="sendReward('${order.memberId}','${order.id}')">发送奖励</button>
							</c:if>
							<c:if test="${order.orderStatus==1}">
							<button type="button" class="btn btn-primary btn-sm" onclick="confirmDeliveryModel();">确认发货</button>
							</c:if>
						</div>
					</div>
				</div>
			</div>
			<!-- /page content -->
			<%@ include file="/WEB-INF/common/foot.jsp"%>
		</div>
	</div>
	<div id="confirmDeliveryModal" class="modal fade" tabindex="-1" role="dialog" data-backdrop="false" aria-hidden="true">
		<div class="modal-dialog modal-md">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">×</span>
					</button>
					<h4 class="modal-title" id="modelTitle">发货信息</h4>
				</div>
				<div class="modal-body">
					<form role="form" data-parsley-validate id="confirmDeliveryForm" class="form-horizontal">
						<input id="orderId" name="orderId" type="hidden" value="${order.id}" />
						<div class="form-group item">
							<label for="fullName2" class="col-sm-3 control-label">物流公司：</label>
							<div class="col-sm-6">
								<select id="logisticsCode" name="logisticsCode" class="form-control" required="required">
									<option value="">请选择</option>
									<c:forEach items="${logisticsList}" var="logistics">
										<option value="${logistics.logisticsCode}">${logistics.logisticsCompany}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="form-group item">
							<label for="username2" class="col-sm-3 control-label">物流单号：</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" id="logisticsNumber" name="logisticsNumber" placeholder="物流单号" required="required"
									data-parsley-length="[0,40]">
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<input type="hidden" id="operate" value="0" /> <input type="hidden" id="indexEdit" />
					<button type="button" class="btn btn-default" onclick="closeModal();">取消</button>
					<button type="button" class="btn btn-success" onclick="confirmDelivery();">保存</button>
				</div>
			</div>
		</div>
	</div>
	<%@ include file="/WEB-INF/common/script.jsp"%>
	<script src="${ctx}resources/js/select/bootstrap-select.js"></script>
 	<script type="text/javascript">
 	$(function() {
		var orderId = $("#orderId").val();
		if (orderId != "") {
		};

	})

	function back() {
		window.location = ctx + "admin/order/toOrderPage";
	}
 	function closeModal() {
		$('#confirmDeliveryModal').modal("hide");
	}
	function confirmDeliveryModel() {
		$('#confirmDeliveryForm').reset();
		$('#confirmDeliveryModal').modal("show");
	 	$("#orderId").val('${order.id}');
	}
	function confirmDelivery() {
		if (!$('#confirmDeliveryForm').parsley().validate()) {
			return;
		}
		swal({
			"title" : "",
			"text" : "正在处理……请稍后",
			"showConfirmButton" : false
		});
		$.ajax({
			url : ctx + "admin/order/confirmDelivery?time=" + (new Date()).getTime(),
			dataType : "json",
			data : $("#confirmDeliveryForm").serialize(),
			success : function(result) {
				if (result.status == "0") {
					swal({
						title : '',
						text : "保存成功"
					}, function() {
						closeModal();
						window.location.reload();
					});
				} else {
					swal({
						title : '',
						text : result.msg,
						type : "error"
					});
				};
			}
		});
	}
	function sendReward(memberId,orderId) {
		$.ajax({
			url : ctx + "admin/order/sendReward?time=" + (new Date()).getTime(),
			dataType : "json",
			data :{
				memberId:memberId,
				orderId:orderId
			},
			success : function(result) {
				if (result.status == "0") {
					swal({
						title : '',
						text : "发送成功"
					}, function() {
						window.location.reload();
					});
				} else {
					swal({
						title : '',
						text : result.msg,
						type : "error"
					});
				};
			}
		});
	}

    Date.prototype.format = function(format)
    {
        var o = {
            "M+" : this.getMonth()+1, //month
            "d+" : this.getDate(),    //day
            "h+" : this.getHours(),   //hour
            "m+" : this.getMinutes(), //minute
            "s+" : this.getSeconds(), //second
            "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
            "S" : this.getMilliseconds(), //millisecond
        }
        if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
            (this.getFullYear()+"").substr(4 - RegExp.$1.length));
        for(var k in o)if(new RegExp("("+ k +")").test(format))
            format = format.replace(RegExp.$1,
                RegExp.$1.length==1 ? o[k] :
                    ("00"+ o[k]).substr((""+ o[k]).length));
        return format;
    };

</script>
</body>
</html>